package com.cloudcc.mobile.parser;

import com.cloudcc.mobile.entity.Vcard;

/**
 * 解析名片扫描返回的串
 * 
 * @author Administrator
 */
public class VcfFileParser {
	private static String[] keys = new String[] { "VERSION", "TEL;CELL",
			"TEL;WORK", "TEL;WORK;FAX", "EMAIL;WORK", "URL;WORK",
			"ADR;WORK;CHARSET=utf-8", "N;CHARSET=utf-8", "FN;CHARSET=utf-8",
			"ORG;PREF;WORK;CHARSET=utf-8", "TITLE;CHARSET=utf-8",
			"ORG;WORK;CHARSET=utf-8", "AUTHOR" };

	public static Vcard parseVcard(String s) {
		String[] ss = s.split("\n");
		Vcard v = new Vcard();
		for (String tmp : ss) {
			if (tmp.startsWith(keys[0])) {
				v.setVersion(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[1])) {
				v.setTelcell(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[3])) {
				v.setTellworkfax(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[2])) {
				v.setTellwork(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[4])) {
				v.setEmailwork(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[5])) {
				v.setUrlwork(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[6])) {
				v.setAdrwork(tmp.substring(tmp.indexOf(":") + 3));
			} else if (tmp.startsWith(keys[7])) {
				v.setN(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[8])) {
				v.setFn(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[9])) {
				v.setOrgprefwork(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[10])) {
				v.setTitle(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[11])) {
				v.setOrgwork(tmp.substring(tmp.indexOf(":") + 1));
			} else if (tmp.startsWith(keys[12])) {
				v.setAuthor(tmp.substring(tmp.indexOf(":") + 1));
			}
		}
		return v;
	}

}
